#
# @lc app=leetcode.cn id=203 lang=python3
#
# [203] 移除链表元素
#

# @lc code=start
# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution:
    def removeElements(self, head: ListNode, val: int) -> ListNode:
        flag = ListNode(0)
        flag.next = head
        pre = flag
        p = pre.next
        while p :
            if p.val == val:
                pre.next = p.next
            else:
                pre = pre.next
            p = pre.next
        return flag.next


# @lc code=end

